package com.pdsu.graduation_design.views;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.pdsu.graduation_design.MainActivity;
import com.pdsu.graduation_design.R;
import com.pdsu.graduation_design.adapter.OrderListAdapter;
import com.pdsu.graduation_design.domain.Order;
import com.pdsu.graduation_design.dto.OrderDTO;
import com.squareup.picasso.Picasso;

import java.text.DecimalFormat;
import java.util.List;

public class LoadingOrderListActivity extends AppCompatActivity {
    private LinearLayout order_main_activity_ll,orderlist_item_ll,orderlist_item_fix_ll,orderlist_item_pre_ll;
    private Context context;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        MainActivity.initOrderData();
        setContentView(R.layout.activity_order_list);

        init();
        bind();
        getData();
    }

    void bind(){
    }
    void init(){
        context=getApplicationContext();
        order_main_activity_ll= findViewById(R.id.order_main_activity_ll);


    }
    @SuppressLint("ResourceAsColor")
    void getData(){
        MainActivity.initOrderData();

        for (Order o: MainActivity.ordersList){
            View ll_pre = View.inflate(context,R.layout.order_list_view_item,null);
            TextView order_list_number=ll_pre.findViewById(R.id.order_list_number);
            TextView order_list_state=ll_pre.findViewById(R.id.order_list_state);
             if(o.getState().equals("d")) {
                order_list_state.setTextColor(R.color.black);
                order_list_state.setText("待发货");

            }
            else {
                continue;

            }
            order_list_number.setText(o.getOrder_number()+"");
            order_main_activity_ll.addView(ll_pre);
            Double all_p_t=0.0d;
            DecimalFormat df = new DecimalFormat("#.00");

            for (OrderDTO od:MainActivity.orderDTOListsMaps.get(o.getOrder_number())){
                LinearLayout item_v= (LinearLayout) View.inflate(context,R.layout.orderlist_item,null);
                ImageView ciamge = item_v.findViewById(R.id.order_list_cimage_iv);
                TextView order_list_cprice_tv= item_v.findViewById(R.id.order_list_cprice_tv);
                TextView order_list_ucnumber_tv= item_v.findViewById(R.id.order_list_ucnumber_tv);
                Picasso.with(context).load(od.getImage()).into(ciamge);
                order_list_cprice_tv.setText(od.getPrice()+"");
                order_list_ucnumber_tv.setText(od.getUcnumber()+"");
                all_p_t=od.getPrice()*od.getUcnumber();
                item_v.setDividerPadding(50);
                order_main_activity_ll.addView(item_v);
            }
            View fix_item = View.inflate(context,R.layout.orderlist_item_fix,null);
            TextView order_list_order_time_tv= fix_item.findViewById(R.id.order_list_order_time_tv);
            TextView order_list_order_allprice_tv= fix_item.findViewById(R.id.order_list_order_allprice_tv);
            order_list_order_time_tv.setText(o.getCreate_time());
            order_list_order_allprice_tv.setText(df.format(all_p_t)+"");
            order_main_activity_ll.addView(fix_item);
            if (o.getState().equals("y")){
                View end_02 = View.inflate(context,R.layout.order_list_fix_end02,null);
                order_main_activity_ll.addView(end_02);
            }else {
                View end_01 = View.inflate(context,R.layout.order_list_fix_end01,null);
                order_main_activity_ll.addView(end_01);


            }

        }
    }
}